package com.zsck.pos.base;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.facebook.stetho.Stetho;
import com.jeremyliao.liveeventbus.LiveEventBus;
import com.zsck.pos.bean.UserInfo;
import com.zsck.pos.net.NetConfig;
import com.zsck.pos.utils.SharePreferenceUtils;

public class POSApplication extends Application {
    private static Context context;
    @Override
    public void onCreate() {
        super.onCreate();
        String accessToken = SharePreferenceUtils.getString(this, "accessToken");
        if(!TextUtils.isEmpty(accessToken)){
            UserInfo userInfo = new UserInfo();
            userInfo.setAccessToken(accessToken);
            userInfo.setAccountId(SharePreferenceUtils.getString(this, "accountId"));
            userInfo.setName(SharePreferenceUtils.getString(this, "name"));
            NetConfig.userInfo = userInfo;
        }
        context = getApplicationContext();
        Stetho.initializeWithDefaults(this);

        LiveEventBus.
                config().
                lifecycleObserverAlwaysActive(true).
                autoClear(false);

    }
    public static Context getContext(){
        return context;
    }
}
